package com.gxa.insurance.service.impl;

import com.gxa.insurance.exception.BusinessException;
import com.gxa.insurance.exception.ExceptionCode;
import com.gxa.insurance.mapper.CouponMapper;
import com.gxa.insurance.mapper.SystemPointMapper;
import com.gxa.insurance.pojo.Coupon;
import com.gxa.insurance.pojo.SystemPoint;
import com.gxa.insurance.service.SystemPointService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author lijunlin
 * @date 2022/6/8
 */
@Service
@Transactional(rollbackFor = {Throwable.class})
public class SystemPointServiceImpl implements SystemPointService {
    @Autowired
    SystemPointMapper systemPointMapper;

    @Override
    public void addSystemPoint(SystemPoint systemPoint) {
        systemPointMapper.addSystemPoint(systemPoint);
    }

    @Override
    public Map<String, Object> selectByPage(Integer currentPage, Integer pageSize) {
        Map<String,Object> map = new HashMap<>();
        Integer integer = systemPointMapper.selectAll();
        List<Map<String, Object>> maps = systemPointMapper.selectByPage((currentPage - 1) * pageSize, pageSize);
        map.put("total",integer);
        map.put("list",maps);
        return map;
    }

    @Override
    public SystemPoint selectById(Integer integer) throws BusinessException {
        SystemPoint systemPoint = systemPointMapper.selectById(integer);
        if (systemPoint == null){
            throw new BusinessException(ExceptionCode.USER_NOT_FONUD);
        }
        return systemPoint;
    }

    @Override
    public void updateSystemPoint(SystemPoint systemPoint) {
        systemPointMapper.updateSystemPoint(systemPoint);
    }

    @Override
    public void deleteSystemPoint(Integer integer) {
        systemPointMapper.deleteSystemPoint(integer);
    }
}
